import java.util.Scanner;

public class demo2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n=scanner.nextInt();
        int m=scanner.nextInt();
        int count=0;
        while(n!=m) {
            boolean have=false;
            for(int i=n-1;i>1;i--) {
                if(n%i==0) {
                    have=true;
                    if(n+i>m) {
                        continue;
                    }
                    n+=i;
                    count++;
                    break;
                }
            }
            if(have==false) {
                System.out.println(-1);
                break;
            }
        }
        System.out.println(count);
    }
}
